package com.trend.config;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.trend.job.IndexDataSyncJob;

//　从Spring3.0，@Configuration用于定义配置类，可替换xml配置文件，被注解的类内部包含有一个或多个被@Bean注解的方法，
//  这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描，
//  并用于构建bean定义，初始化Spring容器。
@Configuration
public class QuartzConfiguration {

	private static final int interval = 10;
	
	 @Bean
	    public JobDetail weatherDataSyncJobDetail() {
	        return JobBuilder.newJob(IndexDataSyncJob.class).withIdentity("indexDataSyncJob")
	        .storeDurably().build();
	    }
	     
	    @Bean
	    public Trigger weatherDataSyncTrigger() {
	        SimpleScheduleBuilder schedBuilder = SimpleScheduleBuilder.simpleSchedule()
	                .withIntervalInHours(interval).repeatForever();
	         
	        return TriggerBuilder.newTrigger().forJob(weatherDataSyncJobDetail())
	                .withIdentity("indexDataSyncTrigger").withSchedule(schedBuilder).build();
	    }
}
